/**
 * Created by qintao30057 on 2016/11/30.
 */
//定义全局变量
var dateFlag=true,dateFlag1=true;
var payProcessLogGrid;//表格
var dhxWins,infoLogWin; //窗口
var oneLogInfo; //一条管理员
//页面布局
var pageObj = {type:"0100",height:[50,,35],paging:true,size:15}
var layoutContainer = create_layout(pageObj);
//初始化操作
$(function(){
    $("html,body").css({overflow:"hidden"});
    initGrid();
    $('#pagingArea').css({"height":"29px","bottom":"5px","left":"3px"});//分页
});
//初始化表格
function initGrid(){
    //获取表格对象
    payProcessLogGrid = layoutContainer.grid[0];
    //定义表格表头
    var columnsInfo=[
        {header:'id',id:'id',hidden:true},
        {header:'交易标识',id:'trade_id',width:120},
        {header:'业务数据',id:'biz_data',width:'*'},
        {header:'堆栈信息',id:'stack_info',width:240},
        {header:'日志级别',id:'degree',width:90, type:'combo'},
        {header:'创建时间',id:'gmt_create',width:130},
        {header:'操作人',id:'operator',width:120}
    ];
    //创建表格
    dmjplugs.grid.createGrid({ sm:'ch',  skin:'dhx_skyblue', srcc:true,  columns:columnsInfo },payProcessLogGrid);
    payProcessLogGrid.setTotal(0);
    payProcessLogGrid.enableEditEvents(false,false,false);
    payProcessLogGrid.getColumnCombo(payProcessLogGrid.getColIndexById('degree')).addOption(logTypeComboData);
    payProcessLogGrid.getColumnCombo(payProcessLogGrid.getColIndexById('degree')).deleteOption("");
    //注册分页事件
    payProcessLogGrid.attachEvent("loadPagingData", function(first, limit){
        findPageGrid(first, limit);
    });
    //注册行点击事件
    payProcessLogGrid.attachEvent("onRowSelect",doOnRowSelected);
    payProcessLogGrid.attachEvent("onRowDblClicked",function () {
        doInfo('info');
    });
    //隐藏掉复选框
    payProcessLogGrid.setColumnHidden(0,true);

    //获取表格数据
    findPageGrid();

}
//根据选择条件,获取表格数据
function findPageGrid(first,limit){
    //初始化表格为空表
    if (!limit) {
        first = 0;
        limit = payProcessLogGrid.getPageRowLimit();
        payProcessLogGrid.clearAll();
        payProcessLogGrid.setTotal(0);
    }
    //分页组件数据
    var postData="pageNo="+parseInt(first/limit+1)+"&pageSize="+limit+"&pageCount="+payProcessLogGrid.getPageTotal();
    //查询条件
    if (typeof (search_Form) == 'object') {
        var formData = search_Form.getFormData();//获取查询表单数据
        var tradeId = search_Form.getInput("tradeId").value;
        if (tradeId == null) tradeId = "";
        var degree = formData.degree;
        if (degree == null) degree = "";
        postData += "&degree=" + degree + "&tradeId=" + tradeId;
        var startTime = search_Form.getInput('startTime').value;
        var endTime = search_Form.getInput('endTime').value;
        postData += "&startTimeStr=" + startTime;
        postData += "&endTimeStr=" + endTime;
    }
    $.ajax({
        url: basePath+'svPayProcessLog/pageFindPayProcessLogGrid',
        type: 'post',
        dataType: 'json', //返回的数据类型
        data:encodeURI(postData),
        success: function (data) {
            if(data&&data.rowCount>0){
                payProcessLogGrid.parse(data.gridr, "json");
                payProcessLogGrid.setTotal(data.rowCount);
                payProcessLogGrid.uncheckAll();
            }
        }
    });
}
//------------------------------------------------顶部操作区----------------------------------------------------------------------
// 顶部查询按钮	注册点击事件
function doOnButtFormInit() {
    if (typeof (butt_Form) == 'object') {
        butt_Form.attachEvent("onButtonClick",function(name,command) {
            if (command == 'info')//详情
                doInfo(command);
            else if (command == 'refresh')//刷新
                doRefresh();
        });
    }
}

//顶部查询框初始化
function doOnSearchFormInit(){
    if (typeof(search_Form) == "object"){
        moduleSearchInit();
        search_Form.attachEvent("onButtonClick", function(name, command) {
            if (command == 'search')
                doRefresh();
            else if(command == 'reset')
                doReset();
        });

        $("input[name='tradeId']").attr('placeholder','请输入交易标识');

        var degree_combo=search_Form.getCombo('degree');
        degree_combo.addOption(logTypeComboData);
        degree_combo.setComboValue('');
        degree_combo.readonly(true);

        var startTime = search_Form.getCalendar('startTime');
        startTime.setDateFormat("%Y-%m-%d %H:%i:%s");
        startTime.showTime();

        var endTime = search_Form.getCalendar('endTime');
        endTime.setDateFormat("%Y-%m-%d %H:%i:%s");
        endTime.showTime();
        //限制日期输入
        $("input[name='startTime']").keyup(function(){
            var tmptxt=$(this).val();
            $(this).val(tmptxt.replace(/[^0-9- :]/g,''));
        }).change(function(){
            var tmptxt=$(this).val();
            tmptxt=tmptxt.replace(/[^0-9- :]/g,'');
            $(this).val(tmptxt);
            if(!checkDateStr('yyyy-MM-dd hh:mm:ss',tmptxt)){
                $func.alert("创建时间起始录入不规范！");
                dateFlag=false;
            }else{
                dateFlag=true;
            }
        }).css("ime-mode", "disabled").attr('placeholder','yyyy-MM-dd hh:mm:ss').attr("maxlength",19);
        $("input[name='endTime']").keyup(function(){
            var tmptxt=$(this).val();
            $(this).val(tmptxt.replace(/[^0-9- :]/g,''));
        }).change(function(){
            var tmptxt=$(this).val();
            tmptxt=tmptxt.replace(/[^0-9- :]/g,'');
            $(this).val(tmptxt);
            if(!checkDateStr('yyyy-MM-dd hh:mm:ss',tmptxt)){
                $func.alert("创建时间截止录入不规范！");
                dateFlag1=false;
            }else{
                dateFlag1=true;
            }
        }).css("ime-mode", "disabled").attr('placeholder','yyyy-MM-dd hh:mm:ss').attr("maxlength",19);

        $('input.dhxlist_txt_textarea').keypress(function(event){
            if(event.keyCode == 13){ //绑定回车
                findPageGrid();
            }
        });
        $('input.dhx_combo_input').keypress(function(event){
            if(event.keyCode == 13){ //绑定回车
                findPageGrid();
            }
        });
    }
}

//刷新按钮
function doRefresh(){
    if(dateFlag1&&dateFlag){
        findPageGrid();
    }else{
        var startTime = search_Form.getInput('startTime');
        search_Form.setItemValue("startTime",new Date(''));
        startTime.value='';
        var endTime = search_Form.getInput('endTime');
        search_Form.setItemValue("endTime",new Date(''));
        endTime.value='';
        findPageGrid();
        dateFlag1=true;
        dateFlag=true;
    }
}

function doReset(){
    search_Form.setFormData({
        tradeId:'',
        degree:''
    });

    var startTime = search_Form.getInput('startTime');
    search_Form.setItemValue("startTime",new Date(''));
    startTime.value='';
    var endTime = search_Form.getInput('endTime');
    search_Form.setItemValue("endTime",new Date(''));
    endTime.value='';
}
//--------------------------------------------------事件方法--------------------------------------------------------------------------

//详情
function doInfo(type) {
    if(type!='info') return;
    var Logs =  getCheckedRowsByGrid(payProcessLogGrid, payProcessLogGrid.getColIndexById('select'));
    if (Logs == null||Logs.length > 1) {
        $func.alert("请选择一行再操作[查看详情]", "red");
        return;
    }
    oneLogInfo=Logs[0];
    if(!oneLogInfo||!oneLogInfo.id){
        $func.alert("所选择行数据有问题,请选择其他行或者刷新页面重试", "red");
        return;
    }
    checkParam(Logs[0].id);

    if(!dhxWins) dhxWins = new dhtmlXWindows();
    dhxWins.setImagePath(basePP + "js/dhtmlx/dhtmlxWindows/codebase/imgs/");
    infoLogWin=dhxWins.createWindow("infoLogWin", 10, 10, 600, 300);
    infoLogWin.center();
    infoLogWin.setModal(true);
    infoLogWin.bringToTop();
    infoLogWin.setText("<span style=\"font-size:14px;\">"+"详情"+"</span>");
    infoLogWin.denyResize();
    infoLogWin.button("minmax1").hide();
    infoLogWin.button("park").hide();
    infoLogWin.attachURL(basePath+"svPayProcessLog/openPayLogInfoWin");
}

//列表鼠标点击事件
function doOnRowSelected(rowID, celInd){
}
